<?php
if (!(defined('IN_IA')))
{
    exit('Access Denied');
}
/**
 * User: 邓志锋 <280160522@qq.com> <http://www.diygw.com>
 * Date: 2018-07-28
 * Time: 下午 6:06
 */
class Home_Diygwcom extends DiygwcomAction
{
    public function index()
    {
        global $_GPC, $_W;
        $dashboardid = $_GPC["dashboardid"];
        if(empty($dashboardid)){
            $dashboardid = $_SESSION['dashboardid'];
        }
        $homepageid= pdo_get(getTableName('PAGE'), array('dashboard_id'=>$dashboardid,'is_home'=>'1','template'=>'mobile'), array('id'));
        if($homepageid){
            $homePage=DiygwcomUtil::to_mobile_url($this->createMobileUrl('page_index', array('m'=>'diygwcom_app','pid'=>$homepageid['id'])));
        }
        if(empty($homePage)){
            $dashboardpage = pdo_getall(getTableName('PAGE'), array('dashboard_id'=>$dashboardid,'template'=>'template'), array('id'),'',array('is_home desc','orderlist asc'));
            if(!empty($dashboardpage)&&is_array($dashboardpage)>0){
                $homePage=DiygwcomUtil::to_mobile_url($this->createMobileUrl('page_index', array('m'=>'diygwcom_app','pid'=>$dashboardpage[0]["id"])));
            }
        }
        if($homePage==""){
            $this->getErrorPage("你访问的地址不存在");
            exit();
        }else{
            header('location:' . $homePage);
        }
    }
}